#include "frame_link_test.h"

#include "dag.h"

#include <fstream>

using namespace dag;
using namespace std;

const char* FrameLinkTest::description() {
	return "frame_link_test";
}

bool FrameLinkTest::run() {
	FrameLink flink1, flink2;
	if (!equal_frame_link(flink1, flink2)) {
		return false;
	}
	
	FrameLink flink3(Link::fullyConnected(10),
					 Link::fullyConnected(5),
					 Link::fullyConnected(3),
					 Link::fullyConnected(7));
	
	if (equal_frame_link(flink1, flink3)) {
		return false;
	}
	
	ofstream of("frame_link_test.bin", ios::binary | ios::trunc | ios::out);
	if (!of.is_open()) {
		return false;
	}
	flink3.serialize(of);
	of.close();
	
	ifstream inF("frame_link_test.bin", ios::binary | ios::in);
	if (!inF.is_open()) {
		return false;
	}
	flink2 = FrameLink::inflate(inF);
	inF.close();
	
	if (!equal_frame_link(flink2, flink3)) {
		return false;
	}
	
	if (equal_frame_link(flink1, flink2)) {
		return false;
	}
	
	return true;
}